/*
运行命令解析：
 --watch:热更新目录
 */
const path = require('path');
const {HomePath}=require('../tools.js');
global.isDev=process.env.NODE_ENV=="development";
global.au={
    tempFilePath:[],
    config:require(HomePath('/au.extensions.js')),
    modulesPath:{}
};
if(global.isDev){
	global.au.config.info.name+="-测试版";
}
//处理清空dist文件夹的插件
const {CleanWebpackPlugin} = require('clean-webpack-plugin');
//处理插件路径
const AuExtensionFilePath=require('../plugs/AuExtensionFilePath');
//vue处理插件
const VueLoaderPlugin = require('vue-loader/lib/plugin');
//初始化插件
const webpackTool=require('../webpack.tool.js');

module.exports = {
    entry: webpackTool.entry({
        'service/background':HomePath('./src/background.js'),
        'service/content':HomePath('./src/main.js'),
        'service/popup':HomePath('./src/popup.js'),
    },this),
    output: {
        filename: '[name].js',
        path: global.isDev?HomePath('/devDist'):HomePath('/dist'),
        publicPath:global.au.config.serviceHost+'/'
    },
    plugins: [
        new VueLoaderPlugin({
            publicPath: global.au.config.serviceHost+'/'
        }),
        new AuExtensionFilePath(),
        new CleanWebpackPlugin(),
    ],
    //devtool: 'inline-source-map',
    module: {
        rules: [
            {
                test:/\.css$/,
                use: [
                    'vue-style-loader',
                    'style-loader',
                    'css-loader',
                    'sass-loader'
                ]
            },
            {
                test:/\.scss$/,
                use: [
                    'style-loader',
                    'css-loader',
                    'sass-loader'
                ]
            },
            {
                test:/\.vue$/, // 处理 .vue 文件
                loader: 'vue-loader'
            },
            {
                test: /\.html$/,
                use: ['html-withimg-loader']
            },
            {
                test: /\.(gif|png|jpgsvg|)$/,
                use: [{
                    loader: "url-loader",
                    options: {
                        //图片小于10kb就是图片地址，大于正常打包成base64格式编码
                        limit: 10000,
                        //输出路径
                        outputPath: 'img/'
                    }
                }]
            },
            {
                test: /\.(eot|svg|ttf|woff|woff2)$/,
                use: {
                    loader: 'url-loader',
                    options: {
                        limit: 100000,
                    }
                }
            }
        ]
    },
    resolve: {
        extensions: [".js", ".jsx", ".json",'.vue'],
        alias: {
            "@": path.join(__dirname, "./src"),
            'vue$': 'vue/dist/vue.esm.js',
        }
    },
    watchOptions: {
        ignored: /core\/*/
    }
};
